package com.example.demo9;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

/**
 * 自定义广播接收者，实现对某些特定的电话拦截
 */
public class OutcallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String data = getResultData();
        SharedPreferences sp=context.getSharedPreferences("config",context.MODE_PRIVATE);
        String data1=sp.getString("phone","");
        Toast.makeText(context, "拦截到了"+data1, Toast.LENGTH_SHORT).show();
        //判断拦截是否一样
        if (data.equals(data1))
        {
            setResultData(null);    //拦截
            Log.d("手机号","拦截成功！");
        }
    }
}
